package com.qf.om;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import java.util.Enumeration;

public class SessionListener implements HttpSessionListener {

    @Override
    public void sessionCreated(HttpSessionEvent se) {
        System.out.println("监听到session创建了！");
        HttpSession session = se.getSession();
//        遍历Session下的属性的名称（用迭代器遍历）
        Enumeration<String> en = session.getAttributeNames();
        while(en.hasMoreElements()){
            String sessionKey = en.nextElement();
            Object value = session.getAttribute(sessionKey);
            System.out.println(sessionKey + "-" + value);
        }
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        HttpSessionListener.super.sessionDestroyed(se);
    }
}
